package com.wzw.springboot.principle.start;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * DefaultListableBeanFactory 是整个bean加载的核心部分，是Spring注册及加载bean的默认实现
 *
 * 二者都是BeanFactory的实现
 * 1.HierarchicalBeanFactory BeanFactory的子接口。扩展了父bean工厂的实现
 *   1.1 ConfigurableBeanFactory ---> XmlBeanFactory ---> DefaultListableBeanFactory
 *   1.2 ApplicationContext ---> ClassPathXmlApplicationContext
 *
 * @author Wangzhiwen
 */
public class ConfigFileStart {

    /**
     * BeanFactory 接口以及它的默认实现类 XmlBeanFactory
     */
    public static void xmlBeanFactory(){
        XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(new ClassPathResource("bean.xml"));
        XmlBean myBean = xmlBeanFactory.getBean("myBean", XmlBean.class);
        System.out.println(myBean);
    }

    /**
     * ApplicationContext ，用于扩展 BeanFactory 中现有的功能
     */
    public static void applicationContextBeanFactory(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        XmlBean myBean = context.getBean("myBean", XmlBean.class);
        System.out.println(myBean);
    }

    public static void main(String[] args) {
        // xmlBeanFactory();
        applicationContextBeanFactory();
    }

}
